home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gchess40.lha / gnuchess4.0p62 / src / ataks.c next >
C/C++ Source or Header  |  1993-06-22  |  2KB  |  72 lines

  1. /*
  2.  * ataks.c - C source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. #include "gnuchess.h"
  24. void
  25. ataks (short int side, short int *a)
  26.  
  27. /*
  28.  * Fill array atak[][] with info about ataks to a square.  Bits 8-15 are set
  29.  * if the piece (king..pawn) ataks the square.  Bits 0-7 contain a count of
  30.  * total ataks to the square.
  31.  */
  32.  
  33. {
  34.   register short u, c, sq;
  35.   register unsigned char *ppos, *pdir;
  36.   short i, piece, *PL;
  37.  
  38. #ifdef NOMEMSET
  39.   for (u = 64; u; a[--u] = 0) ;
  40. #else
  41.   memset ((char *) a, 0, 64 * sizeof (a[0]));
  42. #endif /* NOMEMSET */
  43.   PL = PieceList[side];
  44.   for (i = PieceCnt[side]; i >= 0; i--)
  45.     {
  46.       sq = PL[i];
  47.       piece = board[sq];
  48.       c = control[piece];
  49.       if (sweep[piece])
  50.     {
  51.       ppos = nextpos[piece][sq];
  52.       pdir = nextdir[piece][sq];
  53.       u = ppos[sq];
  54.       do
  55.         {
  56.           a[u] = ((a[u]+1) | c);
  57.           u = ((color[u] == neutral) ? ppos[u] : pdir[u]);
  58.       } while (u != sq);
  59.     }
  60.       else
  61.     {
  62.       pdir = nextdir[ptype[side][piece]][sq];
  63.       u = pdir[sq];        /* follow captures thread for pawns */
  64.       do
  65.         {
  66.           a[u] = ((a[u]+1) | c);
  67.           u = pdir[u];
  68.       } while (u != sq);
  69.     }
  70.     }
  71. }
  72.